import { createRouter, createWebHistory } from 'vue-router';

// 布局组件
import DefaultLayout from '@/components/layout/DefaultLayout.vue';
import AuthLayout from '@/components/layout/AuthLayout.vue';
import AnnouncePublish from '@/views/admin/AnnouncePublish.vue'
import AnnounceList from '@/views/admin/AnnounceList.vue'

// 路由规则
const routes = [
    {
        path: '/',
        redirect: '/user/dashboard'
    },
    {
        path: '/user/dashboard',
        name: 'GymDashboard',
        component: () => import('@/components/GymDashboard.vue') // 直接引入，不使用布局
    },
    {
        path: '/admin/login',
        name: 'AdminLogin',
        component: () => import('@/views/admin/AdminLogin.vue')
    },
    {
        path: '/user/profile',
        name: 'UserProfile',
        component: () => import('@/views/user/UserProfile.vue')
    },
    {
        path: '/user/messages',
        name: 'UserMessages',
        component: () => import('@/views/user/UserMessages.vue')
    },
    {
        path: '/course',
        component: DefaultLayout,
        children: [
            {
                path: 'list',
                name: 'CourseList',
                component: () => import('@/views/course/CourseList.vue')
            },
            {
                path: 'detail/:id',
                name: 'CourseDetail',
                component: () => import('@/views/course/CourseDetail.vue')
            },
            {
                path: 'reservations',
                name: 'Reservation',
                component: () => import('@/views/course/MyReservations.vue')
            }
        ]
    },
    {
        path: '/coach',
        component: DefaultLayout,
        children: [
            {
                path: 'list',
                name: 'CoachList',
                component: () => import('@/views/coach/CoachList.vue')
            }
        ]
    },
    {
        path: '/auth',
        component: AuthLayout,
        children: [
            {
                path: 'login',
                name: 'Login',
                component: () => import('@/views/auth/Login.vue')
            },
            {
                path: 'register',
                name: 'Register',
                component: () => import('@/views/auth/Register.vue')
            }
        ]
    },
    // 后台管理路由 - 简化版
    {
        path: '/admin',
        redirect: '/admin/login'  // 重定向到登录页
    },
    {
        path: '/admin/dashboard',
        name: 'AdminDashboard',
        component: () => import('@/views/admin/AdminDashboard.vue'),
        redirect: '/admin/dashboard/users',
        children: [
            {
                path: 'users',
                name: 'AdminUsers',
                component: () => import('@/views/admin/UserManagement.vue'),
                meta: { title: '用户管理' }
            },
            {
                path: 'coaches',
                name: 'AdminCoaches',
                component: () => import('@/views/admin/CoachManagement.vue'),
                meta: { title: '教练管理' }
            },
            {
                path: 'courses',
                name: 'AdminCourses',
                component: () => import('@/views/admin/CourseManagement.vue'),
                meta: { title: '课程管理' }
            },
            {
                path: 'member-cards',
                name: 'AdminMemberCards',
                component: () => import('@/views/admin/MemberCardManagement.vue'),
                meta: { title: '会员卡管理' }
            },
            {
                path: 'reservations',
                name: 'ReservationManagement',
                component: () => import('@/views/admin/ReservationManagement.vue'),
                meta: { title: '预约管理' }
            },
            {
                path: 'announce-publish',  // 改为子路由
                name: 'AnnouncePublish',
                component: AnnouncePublish,
                meta: { title: '发布公告' }
            },
            {
                path: 'announce-list',  // 改为子路由
                name: 'AnnounceList',
                component: AnnounceList,
                meta: { title: '公告列表' }
            },
            {
                path: 'messages',
                name: 'AdminMessages',
                // component: () => import('@/views/admin/MessageManagement.vue'),
                meta: { title: '消息管理' }
            }
        ]
    },
    // 404 页面
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: () => import('@/views/NotFound.vue')
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes
});

export default router;